package com.izocen.rules.assembler.operator.chain.unit;

import com.izocen.rules.assembler.operator.chain.AbstractOperator;
import com.izocen.rules.common.conts.ScriptOpetorConts;

/**在某个集合
 * @author pengyongjun
 *
 */
public class InOperator extends AbstractOperator{

	public InOperator(String type) {
		super(type);
	}

	/**
	 * alarmCount in ['45','xx22','23']
	 * ['Banana', 'Orange', 'Apple', 'Mango'].indexOf('Apple')  > -1
	 */
	@Override
	protected String format(String message) throws Exception {
		message = this.templateSimpleParam(message);
		String[] arr = message.split(this.operatorType);
		String left  = arr[0].trim();
		String right = arr[1].trim();
		StringBuffer sb = new StringBuffer();
		sb.append(right).append(ScriptOpetorConts.SCRIPT_INDEX_OF);
		sb.append(ScriptOpetorConts.SCRIPT_LEFT_BRACKETS);
		sb.append(left).append(ScriptOpetorConts.SCRIPT_RIGHT_BRACKETS);
		sb.append(ScriptOpetorConts.SCRIPT_BLANK).append(ScriptOpetorConts.SCRIPT_CONTAINS).append(ScriptOpetorConts.SCRIPT_BLANK);
		return sb.toString();
	}

}
